package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import com.tool.btn.FormsOnOffBtn;
import org.come.Frame.TryOntxJframe;
import org.come.model.Eshop;
import org.come.mouslisten.OnlineShopingOpenShopMouslisten;
import org.come.until.CutButtonImage;
import org.come.until.DeviceEshopUntil;
import org.come.until.FormsManagement;
import org.come.Jpanel.TryOntxJpanel;

import com.tool.btn.SpecificBtn;
import com.tool.role.RoleTX;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;

/**
 * 锦绣面板
 * <p>
 * Title : TaobaoCourtJpanel
 * </p>
 *
 * @author : HGC
 * @date : 2019年7月16日 下午5:10:43
 * @version : 1.0.0
 */
public class TaobaoCourtSplendidJpanel extends JPanel {



    private SpecificBtn btnTx,// 特效
            btnZsp,// 装饰品
            btnZj;// 足迹

    private SpecificBtn btnleft,// 人物向左转向
            btnright,// 人物向右转向
            btnxc,// 卸除
            btnsc,// 试穿
            btnhp,// 首页
            btnep,// 末页
            btnsyy,// 上一页
            btnxyy;// 下一页

    private int type = 11;// 当前类别（11: 特效 12: 装饰品 13: 足迹 ）
    private int nowpage = 1;// 当前页数
    //
    private JLabel labpage; // 放置当前页数和总页数
    private int zbs = 0; // 装扮数

    private ShowImageJpanel[] imageJpanel = new ShowImageJpanel[12]; // 展示多宝阁售卖的商品信息
    private Eshop[] eshops = new Eshop[3]; // 保存已穿戴的特效信息（0、1、2分别代表特效、装饰品、足迹）
    //private ShowImageJpanel[] imageJpanels = new ShowImageJpanel[3]; // 展示已穿戴上去的特效信息

    public TaobaoCourtSplendidJpanel()  {
        this.setLayout(null);
        this.setPreferredSize(new Dimension(802, 538));
        this.setOpaque(false);
        this.setBackground(UIUtils.Color_BACK);

        // for (int i = 0; i < 3; i++) {
        //       imageJpanels[i] = new ShowImageJpanel();
        //       imageJpanels[i].setBounds(3 + i * 125, 27, 62, 62);
        //       this.add(imageJpanels[i]);
        //   }

        // 放置当前页数和总页数
        labpage = new JLabel("", SwingConstants.CENTER);
        labpage.setForeground(Color.white);
        labpage.setBounds(647, 337, 58, 17);
        labpage.setFont(UIUtils.TEXT_FONT1);
        this.add(labpage);

        // 人物向左转向
        btnleft = new SpecificBtn("inkImg/number/b8/btn-left.png", 1, "", 15, this);
        btnleft.setBounds(299, 320, 35, 35);
        this.add(btnleft);

        // 人物向右转向
        btnright = new SpecificBtn("inkImg/number/b8/btn-right.png", 1, "", 16, this);
        btnright.setBounds(353, 320, 35, 35);
        this.add(btnright);

        // 卸除
        btnxc = new SpecificBtn("inkImg/number/b8/nex.png", 1, "", 17, this);
        btnxc.setBounds(330, 322, 29, 29);
        this.add(btnxc);

        // 购买
        btnsc = new SpecificBtn("inkImg/number/b8/btnbuy.png", 1, "", 18, this);
        btnsc.setBounds(695, 448, 71, 30);
        this.add(btnsc);

        // 首页
        btnhp = new SpecificBtn("inkImg/number/b8/shou.png", 1, "", 11, this);
        btnhp.setBounds(574, 336, 53, 20);
        this.add(btnhp);

        // 上一页
        btnsyy = new SpecificBtn("inkImg/number/b8/btn1-left.png", 1, "", 12, this);
        btnsyy.setBounds(635, 336, 19, 20);
        this.add(btnsyy);

        // 下一页
        btnxyy = new SpecificBtn("inkImg/number/b8/btn1-right.png", 1, "", 13, this);
        btnxyy.setBounds(708, 336, 19, 20);
        this.add(btnxyy);

        // 末页
        btnep = new SpecificBtn("inkImg/number/b8/wei.png", 1, "", 14, this);
        btnep.setBounds(728, 336, 53, 20);
        this.add(btnep);

        // 展示的特效信息
        for (int i = 0; i < 12; i++) {
            int row = i % 3;
            int col = i / 3;
            imageJpanel[i] = new ShowImageJpanel();
            imageJpanel[i].setBounds(576 + row * 70, 68 + col * 67, 62, 62);
            this.add(imageJpanel[i]);
        }

        // 特效
        btnTx = new SpecificBtn("inkImg/number/b8/topbtn-tx1.png", 1, "", 19, this);
        btnTx.setBounds(150, 0, 64, 28);
        this.add(btnTx);

        // 装饰品
        btnZsp = new SpecificBtn("inkImg/number/b8/topbtn-zsp.png", 1, "", 20, this);
        btnZsp.setBounds(224, 0, 64, 28);
        this.add(btnZsp);

        // 足迹
        btnZj = new SpecificBtn("inkImg/number/b8/topbtn-zj.png", 1, "", 21, this);
        btnZj.setBounds(298, 0, 64, 28);
        this.add(btnZj);

    }




    /**
     * 通过类别获得特效等的集合
     */
    public List<Eshop> returnlEshops(int type) {
        List<Eshop> lEshops = new ArrayList<Eshop>();
        if (type == 11) {
            lEshops = DeviceEshopUntil.getShopingTX();
        } else if (type == 12) {
            lEshops = DeviceEshopUntil.getShopingZS();
        } else if (type == 13) {
            lEshops = DeviceEshopUntil.getShopingZJ();
        }
        return lEshops;
    }

    public void showTaobao() {

        // 根据当前多宝阁的类别去取list
        List<Eshop> lEshops = returnlEshops(type);
        if (lEshops == null) {
            return;
        }

        // 展示多宝阁贩卖的物品信息
        refreshDbgSplendid(lEshops, nowpage);

        // // 打开界面
        // FormsManagement.showForm(39);
    }

    /** 7-17-HGC-start */
    /** 刷新多宝阁物品 */
    public void refresGoodsSplendid() {
        // 获取该类别所展示的物品信息
        List<Eshop> lEshops = returnlEshops(type);
        if (lEshops == null || (lEshops != null && lEshops.size() <= 0)) {
            return;
        }
        nowpage = 1;
        // 刷新界面
        refreshDbgSplendid(lEshops, nowpage);
    }

    /**
     * 重新展示多宝阁界面
     */
    public void refreshDbgSplendid(List<Eshop> lEshops, int nowpage) {
        // 清空界面
        for (int i = 0; i < 12; i++) {
            imageJpanel[i].clearWindow();
        }
        int totalpage = lEshops.size() / 12 + (lEshops.size() % 12 == 0 ? 0 : 1);
        labpage.setText(nowpage + "/" + totalpage);
        // 展示的特效信息
        for (int i = 0; i < ((lEshops.size() - (nowpage - 1) * 12) >= 12 ? 12 : (lEshops.size() - (nowpage - 1) * 12)); i++) {
            imageJpanel[i].getXiaoMouslisten().setEshop(lEshops.get(i + (nowpage - 1) * 12));
            imageJpanel[i].getBtnBuy().setEshop(lEshops.get(i + (nowpage - 1) * 12));
            imageJpanel[i].setName(lEshops.get(i + (nowpage - 1) * 12).getEshopname());
            imageJpanel[i].setValue(lEshops.get(i + (nowpage - 1) * 12).getEshopprice() + "仙玉");
            // imageJpanel[i].getLabImg().setIcon(
            // new ImageIcon(new ImageIcon("img/item/" + lEshops.get(i +
            // (nowpage - 1) * 6).getEshopskin()
            // + ".png").getImage().getScaledInstance(100, 100, 10)));
            imageJpanel[i].getLabImg().setIcon(
                    CutButtonImage.getImage("img/item/" + lEshops.get(i + (nowpage - 1) * 12).getEshopskin() + ".png",
                            62, 62));
            imageJpanel[i].getBtnBuy().setIcon(new ImageIcon("inkImg/number/b8/btnbuy.png"));
            imageJpanel[i].getBtnBuy().setText("购买");
            imageJpanel[i].getBtnBuy().setBtn(1);
            imageJpanel[i].getLabBorder().setIcon(CutButtonImage.getImage("inkImg/number/b8/jinxiubjAJ.png", -1, -1));
        }
    }


    /**
     * 展示已穿戴的特效信息面板
     */
    public void showTxMsg() {
        // 清空界面
        for (int i = 0; i < 3; i++) {
            TryOntxJframe.getTryOntxJframe().getOntxJpanel().getImageJpanels()[i].clearWindow();
        }
        if (this.eshops == null) {
            return;
        }

        List<Eshop> eshops = new ArrayList<Eshop>();
        // 展示的特效信息
        for (int i = 0; i < this.eshops.length; i++) {
            if (this.eshops[i] != null) {
                eshops.add(this.eshops[i]);
            }
        }
        if (eshops == null || (eshops != null && eshops.size() <= 0)) {
            return;
        }
        for (int i = 0; i < eshops.size(); i++) {
            TryOntxJframe.getTryOntxJframe().getOntxJpanel().getImageJpanels()[i].getXiaoMouslisten().setEshop(
                    eshops.get(i));
            TryOntxJframe.getTryOntxJframe().getOntxJpanel().getImageJpanels()[i].getBtnBuy().setEshop(eshops.get(i));
            TryOntxJframe.getTryOntxJframe().getOntxJpanel().getImageJpanels()[i].setName(eshops.get(i).getEshopname());
            TryOntxJframe.getTryOntxJframe().getOntxJpanel().getImageJpanels()[i].setValue(eshops.get(i)
                    .getEshopprice() + "仙玉");
            // TryOntxJframe.getTryOntxJframe().getOntxJpanel().getImageJpanels()[i].getLabImg().setIcon(
            // new ImageIcon(new ImageIcon("img/item/" +
            // eshops.get(i).getEshopskin() + ".png").getImage()
            // .getScaledInstance(100, 100, 10)));
            TryOntxJframe.getTryOntxJframe().getOntxJpanel().getImageJpanels()[i].getLabImg().setIcon(
                    CutButtonImage.getImage("img/item/" + eshops.get(i).getEshopskin() + ".png", 62, 62));
            TryOntxJframe.getTryOntxJframe().getOntxJpanel().getImageJpanels()[i].getBtnBuy().setIcon(
                    CutButtonImage.getImage("inkImg/number/b8/btnbuy1.png", -1, -1));
            TryOntxJframe.getTryOntxJframe().getOntxJpanel().getImageJpanels()[i].getBtnBuy().setBtn(1);
            TryOntxJframe.getTryOntxJframe().getOntxJpanel().getImageJpanels()[i].getBtnBuy().setText("");
            TryOntxJframe.getTryOntxJframe().getOntxJpanel().getImageJpanels()[i].getLabBorder().setIcon(
                    CutButtonImage.getImage("inkImg/number/b8/jinxiubjAJ.png", -1, -1));

        }
    }


    /** 7-17-HGC-end */
    private ImageIcon iconBeiJing;
    private ImageIcon icon;


    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon == null) {
            icon = CutButtonImage.getImage("inkImg/number/b8/jinxiubj.png", 658, 498);
        }
        g.drawImage(icon.getImage(), 135, -1, 658, 498, null);
        g.setFont(UIUtils.TEXT_HURT2);
        g.setColor(new Color(187, 165, 75));


        g.setFont(UIUtils.TEXT_HURT2);
        // g.setColor(new Color(187, 165, 75));
        g.drawString("装扮数:" + zbs, 605, 469);
        if (iconBeiJing == null) {
            iconBeiJing = new ImageIcon("");
        }
        g.drawImage(iconBeiJing.getImage(), 353, 40, 0, 0, this);
        RoleTX.getRoleTX().draw(g, 1);


    }


    //  public ShowImageJpanel[] getImageJpanels() {
    //     return imageJpanels;
    // }

    // public void setImageJpanels(ShowImageJpanel[] imageJpanels) {
    //     this.imageJpanels = imageJpanels;
    // }



    public SpecificBtn getBtnTx() {
        return btnTx;
    }

    public void setBtnTx(SpecificBtn btnTx) {
        this.btnTx = btnTx;
    }

    public SpecificBtn getBtnZsp() {
        return btnZsp;
    }

    public void setBtnZsp(SpecificBtn btnZsp) {
        this.btnZsp = btnZsp;
    }

    public SpecificBtn getBtnZj() {
        return btnZj;
    }

    public void setBtnZj(SpecificBtn btnZj) {
        this.btnZj = btnZj;
    }

    public SpecificBtn getBtnleft() {
        return btnleft;
    }

    public void setBtnleft(SpecificBtn btnleft) {
        this.btnleft = btnleft;
    }

    public SpecificBtn getBtnright() {
        return btnright;
    }

    public void setBtnright(SpecificBtn btnright) {
        this.btnright = btnright;
    }

    public SpecificBtn getBtnxc() {
        return btnxc;
    }

    public void setBtnxc(SpecificBtn btnxc) {
        this.btnxc = btnxc;
    }

    public SpecificBtn getBtnsc() {
        return btnsc;
    }

    public void setBtnsc(SpecificBtn btnsc) {
        this.btnsc = btnsc;
    }

    public SpecificBtn getBtnhp() {
        return btnhp;
    }

    public void setBtnhp(SpecificBtn btnhp) {
        this.btnhp = btnhp;
    }

    public SpecificBtn getBtnep() {
        return btnep;
    }

    public void setBtnep(SpecificBtn btnep) {
        this.btnep = btnep;
    }

    public SpecificBtn getBtnsyy() {
        return btnsyy;
    }

    public void setBtnsyy(SpecificBtn btnsyy) {
        this.btnsyy = btnsyy;
    }

    public SpecificBtn getBtnxyy() {
        return btnxyy;
    }

    public void setBtnxyy(SpecificBtn btnxyy) {
        this.btnxyy = btnxyy;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getNowpage() {
        return nowpage;
    }

    public void setNowpage(int nowpage) {
        this.nowpage = nowpage;
    }

    public JLabel getLabpage() {
        return labpage;
    }

    public void setLabpage(JLabel labpage) {
        this.labpage = labpage;
    }

    public int getZbs() {
        return zbs;
    }

    public void setZbs(int zbs) {
        this.zbs = zbs;
    }

    public ShowImageJpanel[] getImageJpanel() {
        return imageJpanel;
    }

    public void setImageJpanel(ShowImageJpanel[] imageJpanel) {
        this.imageJpanel = imageJpanel;
    }

    public Eshop[] getEshops() {
        return eshops;
    }

    public void setEshops(Eshop[] eshops) {
        this.eshops = eshops;
    }

    public ImageIcon getIconBeiJing() {
        return iconBeiJing;
    }

    public void setIconBeiJing(ImageIcon iconBeiJing) {
        this.iconBeiJing = iconBeiJing;
    }

}
